package com.gxufl.dao;

import java.util.List;

import com.gxufl.Application;
import com.gxufl.entity.Notice;
import com.gxufl.entity.Room;
import com.gxufl.entity.Seat;
import com.gxufl.entity.Ticket;
import com.gxufl.util.JdbcUtil;


public class TicketDao {

	public List<Ticket> findList(String noticeName,String roomName){
		//List<Notice> list =new ArrayList<Notice>();
		//1.构造sql语句
		//2.调用dbutil查询sql结果
		String sql = "select * from movie_ticket where 1";

		if (noticeName != null && !noticeName.isEmpty()) {
			sql = sql + " and noticename  = '" + noticeName + "'";
		}
 
		if (roomName != null && !roomName.isEmpty()) {
			sql += " and roomname = '" + roomName + "'";
		}

		return JdbcUtil.query(sql, Ticket.class);
		
	}
	
	
	//保存方法
	public Ticket save(Ticket ticket) {
		boolean isOK = JdbcUtil.save(ticket);

		if (isOK) {
//			if(ticket.roomname==ticket.roomname && ticket.seatcode == null){
				System.out.println("售票成功"+"\n");
				Application.fn显示主菜单();
//			}else{
//				System.out.println("影院座位以出售！");
//				Application.fn显示主菜单();
//			}
			
		} else {
			System.out.println("售票失败");
		}
		
		return ticket;
	}
//	public void save(Ticket ticket){
//		boolean isOK = JdbcUtil.save(ticket);
//
//		if (isOK) {
//			System.out.println("售票成功");
//			Application.fn显示主菜单();
//		} else {
//			System.out.println("售票失败");
//			Application.fn显示主菜单();
//		}
//	}
//	
	public Ticket findOneByUsertel(String usertel) {
		String sql = "select * from movie_ticket where 1 and usertel = '"+usertel+"'";
		return JdbcUtil.queryOne(sql, Ticket.class);
	}
}
